package com.dcjt.firehotcarpad.moudle

import CarStatePool
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.TextView
import androidx.lifecycle.ViewModelProviders
import com.aries.library.fast.manager.RxJavaManager
import com.aries.ui.view.title.TitleBarView
import com.dcjt.firehotcarpad.R
import com.dcjt.firehotcarpad.fragment.FunctionButtonFragment
import com.dcjt.firehotcarpad.fragment.HandlerOperationFragment
import com.dcjt.firehotcarpad.fragment.MapFragment1
import com.dcjt.firehotcarpad.model.HandleDisasterViewModel
import com.dcjt.firehotcarpad.utils.MarkerToMapType


/**
 * Created by cj on 2021/2/20.
 * Email:codesexy@163.com
 * Function:
 * desc:警情处置界面
 */
class HandleDisasterActivity : BaseActivity() {
    public lateinit var title_Tips: TextView
    lateinit var jqid: String

    companion object {
        fun startHandleActivity(context: Context, title: String, jqid: String) {
            val intent = Intent(context, HandleDisasterActivity::class.java).apply {
                putExtra(
                    "title",
                    title
                ).putExtra("jqid", jqid)
            }
            context.startActivity(intent)
        }
    }

    override fun setTitleBarView(titleBar: TitleBarView) {
        val tips = View.inflate(this, R.layout.layout_title_tips, null)
        title_Tips = tips.findViewById<TextView>(R.id.titleTips)
        titleBar.setLeftTextDrawable(R.drawable.icon_back)
            .setOnLeftTextClickListener { super.onBackPressed() }
            .addLeftAction(titleBar.ViewAction(tips))

    }


    override fun initView(savedInstanceState: Bundle?) {
        jqid = intent.getStringExtra("jqid")
        CarStatePool.get().setCurrentZqidPage(jqid)

        mapFragment = MapFragment1.newInstance()
        leftFragment = HandlerOperationFragment.newInstance(jqid)
        bottomFragment = FunctionButtonFragment.newInstance {
            title_Tips.text = it
        }
        supportFragmentManager
            .beginTransaction()
            .replace(R.id.leftContainer, leftFragment)
            .replace(R.id.rightContainer, mapFragment)
            .replace(R.id.mainBottomContainer, bottomFragment)
            .commitNow()

        val viewModel = ViewModelProviders.of(this).get(HandleDisasterViewModel::class.java)
        //拉取快速回复模版
        viewModel.getTemplate()
        viewModel.setJqid(jqid)

        RxJavaManager.getInstance().setTimer(1000) {
            //警情信息获取详情数据
            viewModel.loadDisasterDetail(jqid)
        }

        CarStatePool.get().getCarState(true)
    }

    override fun onDestroy() {
        super.onDestroy()
        MapOperationEventPool.get()
            .sendAroundWaterMakersDispatch(null, MarkerToMapType.MARKER_REMOVE)

    }

}